using System;
using Microsoft.SPOT;

namespace CobraController
{

  public class Message
  {
    const string sep = "|";
    const string end = "\r\n";

    public string SenderID { get; set; }
    public string TargetID { get; set; }
    public string Command { get; set; }
    public int ParamsCount { get; set; }
    public string[] Params { get; set; }

    public Message()
    {
      SenderID = null;
      TargetID = null;
      Command = null;
      ParamsCount = 0;
      Params = null;
    }

    public override string ToString()
    {
      string ts = string.Empty;
      if (ParamsCount == 0)
        ts = SenderID + sep + TargetID + sep + Command + sep + ParamsCount + end;
      else
      {
        ts = SenderID + sep + TargetID + sep + Command + sep + ParamsCount + sep;
        for (int x = 0; x < ParamsCount; x++)
        {
          ts += Params[x] + (x < ParamsCount-1 ? sep : string.Empty);
        }
        ts += end;
      }
      return ts;
    }

    //public static string PrintMessageNP(ID senderID, ID targetID, Command command, int paramsCount = 0)
    //{
    //  string pm = senderID + "|";
    //  pm += targetID + "|";
    //  pm += command + "|";
    //  pm += paramsCount + "\r\n";
    //  return pm;
    //}

    //public static string PrintMessageWP(ID senderID, ID targetID, Command command, int paramsCount, string[] parameters)
    //{ 
    //  string pm = senderID + "|";
    //  pm += targetID + "|";
    //  pm += command + "|";
    //  pm += paramsCount + "|";
    //  for (int x = 0; x < paramsCount; x++ )
    //  {
    //    pm += parameters[x] + (x < paramsCount ? "|" : "");
    //  }
    //    return pm;
    //}
  }

  public class MTS
  {
    public Message MyMessage { get; set; }
    public string MyTransport { get; set; }

    public MTS()
    {
      MyMessage = null;
      MyTransport = string.Empty;
    }

  }
  class Command
  {
    public const string Who               = "who";
    public const string SetDateTime       = "setdatetime";
    public const string GetDateTime       = "getdatetime";
    public const string SetCounters       = "setcounters";
    public const string GetCounters       = "getcounters";
    public const string GetDow            = "getdow";
    public const string GarageState       = "garagestate";
    public const string CommandNotValid   = "Not a valid command";
		public const string GetSensorValues		= "getsensorvalues";
  }

  class ID
  {
    public const string HAMS = "hams";
    public const string COBRA = "cobra";
    public const string PANDA = "panda";
  }

  class Transport
  {
    public const string SER = "COM";
    public const string NET = "NET";
    public const string LOC = "LOC";
  }

  class Garage
  {
    public const string Open = "Open";
    public const string Closed = "Closed";
  }

}
